#pragma once

class Callbackable;
class FastBlockQueue;

struct TimerCommand
{
	enum TYPE {ADD_TIMER_COMMAND,DELETE_TIMER_COMMAND};
	int type;
	UINT handler;
	UINT period;
	Callbackable* callback;
};

struct Timer
{
	UINT dueTime;
	UINT period;

	LARGE_INTEGER begin;
	_int64 counter;
	Callbackable* callback;
};

class HighPerformanceTimerThread
{
public:
	HighPerformanceTimerThread(FastBlockQueue& queue);
	void Run();

private:
	void AddTimer(UINT handler,UINT period,Callbackable* callback);
	void DeleteTimer(UINT handler);
	bool IsEmpty() const
	{
		return m_timers.empty();
	}
	void TriggerTimer(LARGE_INTEGER const& freqtime);
	void OnCommand(bool& quitFlag);
	void ProcessCommand(bool& quitFlag);


	FastBlockQueue& m_queue;
	std::map<UINT,Timer> m_timers;
};
